home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: Jane Harper <jharper@ix.netcom.com>
- Newsgroups: comp.lang.c
- Subject: Re: Probs with prototype mixes with Functions
- Date: Sat, 20 Apr 1996 09:06:54 -0700
- Organization: Netcom
- Message-ID: <31790B9E.3EE@ix.netcom.com>
- References: <dward.1.000DC9CA@melbpc.org.au>
- NNTP-Posting-Host: sjx-ca11-09.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-NETCOM-Date: Sat Apr 20 11:09:37 AM CDT 1996
- X-Mailer: Mozilla 2.01 (Win95; U)
-
- Darren Ward wrote:
- >
- > Could anyone help me with the following?
- >
- > when making a function such as:
- >
- > float convert(int celcius)
- > {
- > float faranheit;
- > faranheit = ((float)celcius*9/5)+32;
- > return faranheit;
- > }
-
- When you multiply celcius (cast to float) by 9/5 (an integer division),
- celcius is cast back to an int. Therefore, your return is an int, not a
- float. If you want a float return, change 9/5 to 9.0/5.0. :D
-
- BTW, you may also want to check your spelling .. it's celSius and
- FAHRenheit. ;0
-
- J.
-